package models

type Version struct {
	Id          int    `xorm:"not null pk autoincr INT(11)"`
	Version     int    `xorm:"comment('版本号') INT(11)"`
	Versionname string `xorm:"comment('版本名称') VARCHAR(255)"`
	Reason      string `xorm:"comment('升级原因') VARCHAR(255)"`
	Appurl      string `xorm:"comment('版本url') VARCHAR(500)"`
	Platform    string `xorm:"comment('1 代表android  2 代表ios') ENUM('1','2')"`
	Type        string `xorm:"default '1' comment('1 终端  2教练端3学员端，4-1700版本的终端') ENUM('1','2','3','4')"`
	District    string `xorm:"default '' comment('地区县') VARCHAR(30)"`
	Content     string `xorm:"default '' comment('地区县') VARCHAR(255)"`
}

type VersionList struct {
	Id          int    `json:"id"`
	Versionname string `json:"versionname"`
	Reason      string `json:"reason"`
	District    string `json:"district"`
	City        string `json:"city" xorm:"-"`
	Content     string `json:"content"`
}

func (c *Version) GetVersion() (list []*VersionList, err error) {
	err = engine.Table("dts_version").
		Where("id <= ?", 12).Find(&list)
	return list, err
}

func (c *Version) ChangeVersion(id string) bool {
	_, err := engine.Exec("update dts_version set district = ? where id = ?", "999999", id)
	return err == nil
}

func (c *Version) OpenVersion(id, city string) bool {
	_, err := engine.Exec("update dts_version set district = ? where id = ?", city, id)
	return err == nil
}
